package cn.edu.ujn.booksshop.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.ujn.booksshop.dao.Author;
import cn.edu.ujn.booksshop.dao.AuthorMapper;
import cn.edu.ujn.util.Page;
@Service
@Transactional
public class AuthorServiceImpl implements IAuthorService {

	@Autowired
	private AuthorMapper authorDao;
	@Override
	public int deleteByPrimaryKey(Integer authorid) {
		// TODO Auto-generated method stub
		return this.authorDao.deleteByPrimaryKey(authorid);
	}

	@Override
	public int insert(Author row) {
		// TODO Auto-generated method stub
		return this.authorDao.insert(row);
	}

	@Override
	public int insertSelective(Author row) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Author selectByPrimaryKey(Integer authorid) {
		// TODO Auto-generated method stub
		return this.authorDao.selectByPrimaryKey(authorid);
	}

	@Override
	public int updateByPrimaryKeySelective(Author row) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKeyWithBLOBs(Author row) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKey(Author row) {
		// TODO Auto-generated method stub
		return this.authorDao.updateByPrimaryKey(row);
	}

	@Override
	public Page<Author> selectAll(Integer page,Integer rows,String authorName) {
		// TODO Auto-generated method stub
		List<Author> selectAll = this.authorDao.selectAll((page-1)*rows,rows,authorName);
		Integer total = this.selectAuthorListCount();
		Page<Author> pages = new Page<Author>();
		pages.setPage(page);
		pages.setRows(selectAll);
		pages.setSize(rows);
		pages.setTotal(total);
		
		return pages;
	}

	@Override
	public Integer selectAuthorListCount() {
		// TODO Auto-generated method stub
		return this.authorDao.selectAuthorListCount();
	}
}
